<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="Bootstrap/js/jquery-1.11.1.min.js"></script>
    <link href="Bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <style>
        *{margin: 0;padding: 0;list-style: none}
        header{background-color: #20a1a1;height: 40px;width: 100%;color: white;line-height: 40px;text-align: center;position: fixed;top: 0px;z-index: 2}
        .back{font-size: 13px;font-weight: bold;margin-left: 10px;float: left}
        footer{width: 100%;height: 48px;position: fixed;bottom: 0px;line-height: 48px}
        footer div{height: 48px;float: left}
        .totalPrice{float: right;color: red;font-size: 14px ;margin-right: 10px;}
        .order{margin-top: 40px}
        .placeorder .store_img{width: 15px;height: 15px;margin: 5px 0 0 10px}
        .store{width: 100%;height: 25px;border-bottom: 1px solid #f8f8ff;line-height: 25px;font-size: 13px;}
        .store_name{position: absolute;margin:1px 5px}
        .product img{width: 75px;height: 75px;border-radius: 10px;margin: 3px 0px 5px 10px}
        .product ul{background-color:#F0F0F0;}
        .product{width: 100%;height: 82px;margin-top: 2px;background-color: white;border-bottom: 4px solid #f8f8ff;}
        .product_title{position: absolute;margin-left: 1%;font-size: 13px;padding: 3px;color: black;margin-top: 4px}
        .product .price{position: absolute;color: red;font-size: 15px;margin-top: 55px;font-weight: bold;margin-left: 2%}
        .number{margin-top: 56px;font-size: 13px;color: gray;float: right;margin-right: 15px}
        .kind{position: absolute;margin-top: 30px;font-size: 12px;color: gray;margin-left: 11px}
        .taste{position: absolute;margin-top: 30px;font-size: 12px;color: gray;margin-left: 44px}
        .message{width: 100%;height: 43px;border-bottom: 4px solid #f8f8ff;line-height: 40px;}
        .message .title{display: inline-block;margin-left: 10px;font-size: 14px;font-family: "微软雅黑"}
        .msg{padding-left: 20px;height: 30px;border: 0;width: 67%}
        .little_totalPrice{float: right;color: red;font-size: 14px;margin-right: 10px;margin-top: 8px}
        .time{width: 100%;height: 43px;border-bottom: 4px solid #f8f8ff;line-height: 40px;}
        .time .date{height: 30px;border: 0;width: 35%}
        .time .choosetime{border: 0;height: 30px;width: 35%}
        .time .title{display: inline-block;margin-left: 10px;font-size: 14px;font-family: "微软雅黑"}
        .little{margin-bottom: 30px;}
    </style>
    <script>
        var userId = 2;
        $(function () {
            //查询已选结算的商品
            var addressUrl = decodeURIComponent(location.href);
            var rs = addressUrl.indexOf("gotobuyingPRO");
            if(rs==-1){
                var ids = (location.href).split("UIDS");
                var productItemIds = ids[ids.length-1];
                var businessItemIds = ids[ids.length-2];
                var data = {"productItemIds":productItemIds,"businessItemIds":businessItemIds};
                var url = "http://obao.tunnel.2bdata.com/cart!findBuyingBill.htm";
                $.post(url,data,function (data) {
                    var html = "";
                    // 一个商家开始
                    for(var i = 0;i<data.length;i++){
                        var businessImg = "http://obao.tunnel.2bdata.com/upload/business/"+data[i].business.photo;
                        html+="<ul class='order'>";
                        html+=" <li class='store'>";
                        html += "<input type='hidden' class='businessId' value='"+data[i].business.businessId+"' />"
                        html+="  <img src='"+businessImg+"' class='store_img'>";
                        html+="         <span class='store_name'>"+data[i].business.name+"</span>";
                        html+="  </li>";
                        html+="<li>";
                        html+=" <ul>";
                        for(var j = 0;j<data[i].productItems.length;j++){
                            var productImg = "http://obao.tunnel.2bdata.com/upload/product/"+data[i].productItems[j].product.productImg;
                            // 一个商品开始

                            html+="     <a href='info.html?"+data[i].productItems[j].product.productId+"'>";
                            html+="         <li class='product'>";
                            html+="             <img src='"+productImg+"'>";
                            html+="                 <span class='product_title'>"+data[i].productItems[j].product.productName+"</span>";
                            html+="                 <span class='kind'>"+data[i].productItems[j].productSize.size+"</span>";
                            html+="                 <span class='taste'>"+data[i].productItems[j].productFlavor.name+"</span>";
                            html+="                 <span class='price'>";
                            html+="                     <span>￥</span><span class='pric'>"+data[i].productItems[j].productSize.price+"</span>元</span>";
                            html+="                 <span class='number'>";
                            html+="                     <span>x</span><span class='num'>"+data[i].productItems[j].productNumber+"</span>";
                            html+="                 </span>";
                            html+="         </li>";
                            html+="     </a>";
                            //一个商品结束
                        }
                        html+=" </ul>";
                        html+="</li>";
                        html+="<li class='message'>";
                        html+=" <span class='title'>买家留言:</span>";
                        html+=" <input type='text' placeholder='对本次交易的说明' class='msg'>";
                        html+="</li>";
                        html+="<li class='time'>";
                        html+=" <span class='title'>取餐时间:</span>";
                        html+=" <input type='date' class='date' value='2005-10-22'>";
                        html+="     <input type='time' class='choosetime' value='12:20'>";
                        html+="</li>";
                        html+="</ul>";
                        <!--一个商家结束-->
                    }
                    $(".placeorder").html(html);
                    totalPrice();
                });
            }else{
                var parmas = addressUrl.split("PRO");
                var html = "";
                // 一个商家开始
                    var businessImg = "http://obao.tunnel.2bdata.com/upload/business/"+parmas[3];
                    html+="<ul class='order'>";
                    html+=" <li class='store'>";
                    html += "<input type='hidden' class='businessId' value='"+parmas[1]+"' />"
                    html+="  <img src='"+businessImg+"' class='store_img'>";
                    html+="         <span class='store_name'>"+parmas[2]+"</span>";
                    html+="  </li>";
                    html+="<li>";
                    html+=" <ul>";
                        var productImg = "http://obao.tunnel.2bdata.com/upload/product/"+parmas[7];
                        // 一个商品开始
                        html+="     <a href='info.html?"+parmas[4]+"'>";
                        html+="         <li class='product'>";
                        html+="             <img src='"+productImg+"'>";
                        html+="                 <span class='product_title'>"+parmas[5]+"</span>";
                        html+="                 <span class='kind'>"+parmas[6]+"</span>";
                       // html+="                 <span class='taste'>"+data[i].productItems[j].productFlavor.name+"</span>";
                        html+="                 <span class='price'>";
                        html+="                     <span>￥</span><span class='pric'>"+parmas[8]+"</span>元</span>";
                        html+="                 <span class='number'>";
                        html+="                     <span>x</span><span class='num'>"+parmas[parmas.length-1]+"</span>";
                        html+="                 </span>";
                        html+="         </li>";
                        html+="     </a>";
                        //一个商品结束
                    html+=" </ul>";
                    html+="</li>";
                    html+="<li class='message'>";
                    html+=" <span class='title'>买家留言:</span>";
                    html+=" <input type='text' placeholder='对本次交易的说明' class='msg'>";
                    html+="</li>";
                    html+="<li class='time'>";
                    html+=" <span class='title'>取餐时间:</span>";
                    html+=" <input type='date' class='date' value='2005-10-22'>";
                    html+="     <input type='time' class='choosetime' value='12:20'>";
                    html+="</li>";
                    html+="</ul>";
                    <!--一个商家结束-->
                $(".placeorder").html(html);
                totalPrice();
            }

        });

        function totalPrice(){
            var  order = $(".order").find(".product");
            var  price=0;
            var num=0;
            for(var i=0;i<order.length;++i){
                price+=parseFloat($(order[i]).find(".pric").html()*$(order[i]).find(".num").html());
                num+=parseFloat($(order[i]).find(".num").html());
            }
            $(".total_price").html(parseFloat(price));
        }

        function hidden() {
            var ifr1=window.parent.document.getElementById('footer');
            ifr1.style.display="none";
        }
        function show() {
            var ifr1=window.parent.document.getElementById('footer');
            ifr1.style.display="";
        }
    </script>
</head>
<body onload="hidden()">
<header>
    <span class="back" onclick="history.go(-1);show()"><</span>
    <span class="business_title_name" style="font-size: 15px;font-weight: bold">确认订单</span>
</header>
<div class="placeorder">
    <!--一个商家开始-->
</div>
<div style="height: 50px"></div>
<footer>
    <div style="width: 70%;background-color:#F0F0F0">
            <span class="totalPrice">
                <span style="color: black;font-weight: bold">合计:</span>
                <span class="price" style="font-weight: bold">￥<span class="total_price"></span>元</span>
            </span>
    </div>
    <div style="width: 30%;background-color:#FF4500 ;font-weight: bold;color: white;text-align: center;font-size: 13px;" onclick="statements()">提交订单</div>
    <script>
        function statements() {
            var orders = $(".order");
            var data = "[";
            var orderNum =0;
            for(var i = 0; i < orders.length; ++i) { //遍历商家
                var product = orders.eq(i).find("a");
                var dateTime = orders.eq(i).find(".date").val() + " " + orders.eq(i).find(".choosetime").val()+":00";
                var message =  orders.eq(i).find(".msg").val()
                for(var j = 0; j < product.length; ++j) { //遍历商家下商品订单
                    var pid = product.eq(j).attr("href").split("?")[1];
                    data += '{"productId":"'+pid+'"';
                    data += ',"number":"'+product.eq(j).find('.num').text()+'"';
                    data +=  ',"flavor":"'+product.eq(j).find('.kind').text()+'"';
                    data += ',"size":"'+product.eq(j).find('.taste').text()+'"';
                    data += ',"finishTime":"'+dateTime+'"';
                    data +=  ',"remark":"'+message+'"';
                    data +=  ',"userId":"'+userId +'"},';
                    ++orderNum;
                }
            }
            data += "]";
            data = data.substring(0,data.length-2)+"]";
            $.ajax({
                url:"http://obao.tunnel.2bdata.com/order_statement.htm",
                type:"post",
                data:{"orderString":data},
                success:function (data) {
                }
            })
        }
    </script>
</footer>
</body>
</html>